package com.sfx.算法专题.双指针.同向双指针.普通双指针;

/**
 * Created with IntelliJ IDEA.
 * Description:https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/
 * User: sfx
 * Date: 2023-07-18
 * Time: 12:29
 */
public class Code_6_removeDuplicates2 {

    static class Solution {
        public int removeDuplicates(int[] nums) {
            int k = 2;
            int n = nums.length;
            int cur = 0;
            int dest = 0;
            while(cur < n) {
                if(dest < k || nums[dest - k] != nums[cur]) {
                    nums[dest++] = nums[cur];
                }
                cur ++;
            }
            return dest;
        }
    }
}
